/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package memberserviceconsumer;
import java.util.Date;
import net.office_on_the.ducs.services.*;
import java.util.List;
import java.util.Vector;
import javax.swing.DefaultListModel;
import javax.swing.table.DefaultTableModel;
import timeConversion.DateToGregorian;

 /*
 * @author Duc
 */
public class MemberClient {
    public String invoke(){
        MemberService service = new MemberService();
        Member port = service.getMemberPort();
        List memList=port.getAllMem();
        Mem mem0=(Mem)memList.get(0);
        return mem0.getName();
    }
    public void addNewMem(){
        Mem newmem=new Mem();
        newmem.setAddress("502 E2");
        newmem.setBirthYear("1987");
        newmem.setEmail("ab@yoh.com");
        newmem.setGenre(true);
        newmem.setMemberCode(5);
        newmem.setName("Due Bwe");
        newmem.setPhoneNumber("0933456123");
        newmem.setParticipateDate(DateToGregorian.date2Gregorian(new Date()));
        MemberService service = new MemberService();
        Member port = service.getMemberPort();
        port.persistMem(newmem);
    }
    public DefaultListModel getAllMem(){
        
        MemberService service = new MemberService();
        Member port = service.getMemberPort();
        List memList=port.getAllMem();
        int memNum=memList.size();
        String[] nameList=new String[memNum];
        DefaultListModel listModel = new DefaultListModel();
//        for (int index=0;index<memNum;index++){
//            Mem memi=(Mem)memList.get(index);
//            nameList[index]=memi.getName();
//        }
        for(Object o: memList) {
            Mem memi=(Mem)o;

            listModel.addElement((memi.getName()));
        }

        return listModel;
    }
    public DefaultTableModel getMemTable(){
        DefaultTableModel tableModel=new DefaultTableModel();
        MemberService service = new MemberService();
        Member port = service.getMemberPort();
        List memList=port.getAllMem();
        tableModel.addColumn("Member Code");
        tableModel.addColumn("Name");
        tableModel.addColumn("Address");
        tableModel.addColumn("Birth Year");
        tableModel.addColumn("Email");
        tableModel.addColumn("Phone Number");
        tableModel.addColumn("Participate Date");
        for(Object o: memList){
            Mem memo=(Mem)o;
            Vector rowData=new Vector();
            rowData.add(memo.getMemberCode());
            rowData.add(memo.getName());
            rowData.add(memo.getAddress());
            rowData.add(memo.getBirthYear());
            rowData.add(memo.getEmail());
            rowData.add(memo.getPhoneNumber());
            rowData.add(memo.getParticipateDate().toString());
            tableModel.addRow(rowData);
        }
        return tableModel;
    }

}
